home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 12.6 KB | 416 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWContxt.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWCONTXT_H
- #include "FWContxt.h"
- #endif
-
- #ifndef FWVIEW_H
- #include "FWView.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- #ifndef FWFCTINF_H
- #include "FWFctInf.h"
- #endif
-
- #ifndef FWODGEOM_H
- #include "FWODGeom.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWSOMENV_H
- #include "FWSOMEnv.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- //========================================================================================
- // Runtime Informations
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment framework
- #endif
-
- //========================================================================================
- // class FW_CWindowContext
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CWindowContext)
-
- //----------------------------------------------------------------------------------------
- // FW_CWindowContext::FW_CWindowContext
- //----------------------------------------------------------------------------------------
-
- FW_CWindowContext::FW_CWindowContext(Environment* ev, ODFacet* odFacet) :
- FW_CGraphicContext(ev),
- fTempDevice(NULL),
- fODWindow(NULL)
- {
- InitWindowContext(ev, odFacet->GetWindow(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindowContext::FW_CWindowContext
- //----------------------------------------------------------------------------------------
-
- FW_CWindowContext::FW_CWindowContext(Environment* ev, ODWindow *odWindow) :
- FW_CGraphicContext(ev),
- fTempDevice(NULL),
- fODWindow(NULL)
- {
- InitWindowContext(ev, odWindow);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindowContext::InitWindowContext
- //----------------------------------------------------------------------------------------
-
- void FW_CWindowContext::InitWindowContext(Environment* ev, ODWindow *odWindow)
- {
- FW_ASSERT(odWindow != NULL);
- fODWindow = odWindow;
- fODWindow->Acquire(ev);
-
- ODFacet *facet = fODWindow->GetRootFacet(ev);
-
- FW_CAcquiredODShape aqClipShape = AcquireClipShape(ev);
-
- /*
- [HLX] there is a problem trying to reuse the graphic device of the root frame.
- First of all if the graphic device has a fContext, it should be suspended. Also
- now that we are running static part I don't know what the effect is. We need to
- look at that. Might be able to put it back when we move the graphic to a SOM DLL.
-
- FW_CGraphicDevice* device = FW_GetFacetGraphicDevice(ev, facet);
- if (device == NULL)
- {
- fTempDevice = new FW_CGraphicDevice(ev, facet->GetCanvas(ev));
- device = fTempDevice;
- }
-
- InitGraphicContext(device,
- NULL,
- aqClipShape);
- */
-
- fTempDevice = FW_PrivGDev_CreateFromODCanvas(ev, facet->GetCanvas(ev));
- FW_FailOnEvError(ev);
-
- InitGraphicContext(fTempDevice,
- NULL,
- aqClipShape);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindowContext::~FW_CWindowContext
- //----------------------------------------------------------------------------------------
-
- FW_CWindowContext::~FW_CWindowContext()
- {
-
- if (fODWindow)
- {
- FW_SOMEnvironment ev;
- fODWindow->Release(ev);
- }
-
- if (fTempDevice)
- FW_PrivGDev_Release(fTempDevice);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindowContext::AcquireClipShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_CWindowContext::AcquireClipShape(Environment* ev)
- {
- #ifdef FW_BUILD_MAC
- FW_CRect rect(fODWindow->GetPlatformWindow(ev)->portRect);
- #endif
- #ifdef FW_BUILD_WIN
- FW_CPlatformRect clientRect;
- ::GetClientRect(fODWindow->GetPlatformWindow(ev), &clientRect);
- FW_CRect rect(clientRect);
- #endif
-
- return ::FW_NewODShape(ev, rect);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindowContext::Reset
- //----------------------------------------------------------------------------------------
-
- void FW_CWindowContext::Reset()
- {
- FW_CAcquiredODShape aqClipShape = AcquireClipShape(fEnvironment);
- PrivReset(NULL, aqClipShape);
- }
-
- //========================================================================================
- // class FW_CFrameContext
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CFrameContext)
-
- //----------------------------------------------------------------------------------------
- // FW_CFrameContext::FW_CFrameContext
- //----------------------------------------------------------------------------------------
- // invalidShape is in Frame coordinate
-
- FW_CFrameContext::FW_CFrameContext(Environment* ev, ODFacet *facet, ODShape* invalidShape) :
- FW_CGraphicContext(ev),
- fFacet(facet)
- {
- FW_ASSERT(facet != NULL);
-
- FW_CAcquiredODTransform aqFrameTransform = facet->AcquireFrameTransform(ev, NULL);
-
- FW_CAcquiredODShape aqClipShape = FW_CopyAndRelease(ev, fFacet->AcquireAggregateClipShape(ev, NULL));
- if (invalidShape != NULL)
- aqClipShape->Intersect(ev, invalidShape);
-
- InitGraphicContext(FW_GetFacetGraphicDevice(ev, fFacet),
- aqFrameTransform,
- aqClipShape);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFrameContext::~FW_CFrameContext
- //----------------------------------------------------------------------------------------
-
- FW_CFrameContext::~FW_CFrameContext()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFrameContext::Reset
- //----------------------------------------------------------------------------------------
-
- void FW_CFrameContext::Reset()
- {
- FW_CAcquiredODTransform aqContentTransform = fFacet->AcquireFrameTransform(fEnvironment, NULL);
- FW_CAcquiredODShape aqClipShape = FW_CopyAndRelease(fEnvironment, fFacet->AcquireAggregateClipShape(fEnvironment, NULL));
-
- PrivReset(aqContentTransform, aqClipShape);
- }
-
- //========================================================================================
- // class FW_CPlatformGraphicContext
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CPlatformGraphicContext)
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformGraphicContext::FW_CPlatformGraphicContext
- //----------------------------------------------------------------------------------------
-
- FW_CPlatformGraphicContext::FW_CPlatformGraphicContext(Environment* ev, ODFacet *facet, ODShape* invalidShape) :
- FW_CGraphicContext(ev),
- fFacet(facet)
- #ifdef FW_BUILD_MAC
- ,fMacPort(NULL)
- #endif
- {
- FW_ASSERT(facet != NULL);
-
- // InitGraphicContext expect clip shape in content coordinates
- FW_CAcquiredODShape aqClipShape(FW_CopyAndRelease(ev, fFacet->AcquireAggregateClipShape(ev, NULL)));
- FW_FrameToContent(ev, fFacet->GetFrame(ev), aqClipShape);
-
- if (invalidShape != NULL)
- aqClipShape->Intersect(ev, invalidShape);
-
- InitGraphicContext(FW_GetFacetGraphicDevice(ev, fFacet),
- NULL,
- aqClipShape);
-
- #ifdef FW_BUILD_MAC
- PrivMacAlignOrigin(ev);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformGraphicContext::~FW_CPlatformGraphicContext
- //----------------------------------------------------------------------------------------
-
- FW_CPlatformGraphicContext::~FW_CPlatformGraphicContext()
- {
- #ifdef FW_BUILD_MAC
- if (fMacPort != NULL)
- {
- GrafPtr port;
- ::GetPort(&port);
- ::SetPort(fMacPort);
- ::SetOrigin(-fMacOrigin.h, -fMacOrigin.v);
- ::SetPort(port);
- }
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CPlatformGraphicContext::Reset
- //----------------------------------------------------------------------------------------
-
- void FW_CPlatformGraphicContext::Reset()
- {
- FW_CAcquiredODShape aqClipShape(FW_CopyAndRelease(fEnvironment, fFacet->AcquireAggregateClipShape(fEnvironment, NULL)));
-
- PrivReset(NULL, aqClipShape);
-
- #ifdef FW_BUILD_MAC
- PrivMacAlignOrigin(fEnvironment);
- #endif
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CPlatformGraphicContext::PrivMacAlignOrigin
- //----------------------------------------------------------------------------------------
-
- void FW_CPlatformGraphicContext::PrivMacAlignOrigin(Environment* ev)
- {
- FW_CAcquiredODTransform aqContentTransform = fFacet->AcquireContentTransform(ev, NULL);
- FW_CPoint origin(FW_kZeroPoint);
- origin.Transform(ev, aqContentTransform);
-
- ::GetPort(&fMacPort);
- fMacOrigin.h = fMacPort->portRect.left;
- fMacOrigin.v = fMacPort->portRect.top;
-
- ::SetOrigin(- FW_FixedToInt(origin.x), - FW_FixedToInt(origin.y));
- }
- #endif
-
- //========================================================================================
- // CLASS FW_CViewContext
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CViewContext)
-
- //----------------------------------------------------------------------------------------
- // FW_CViewContext::FW_CViewContext
- //----------------------------------------------------------------------------------------
- // invalidShape is in view content coordinates
-
- FW_CViewContext::FW_CViewContext(Environment* ev, FW_CView *view, ODFacet* odFacet, ODShape* invalidShape) :
- FW_CGraphicContext(ev),
- fView(view),
- fFacet(odFacet)
- {
- FW_ASSERT(fFacet);
-
- if (fView == NULL)
- {
- FW_CFrame* frame = FW_CFrame::ODtoFWFrame(ev, odFacet->GetFrame(ev));
- fView = frame->GetContentView(ev);
- }
-
- FW_CAcquiredODTransform aqTransform = PrivAcquireTransform(ev);
- FW_CAcquiredODShape aqClipShape = PrivAcquireClipShape(ev);
-
- // Intersect it with the invalidShape (already in view content coordinates)
- if (invalidShape != NULL)
- aqClipShape->Intersect(ev, invalidShape);
-
- InitGraphicContext(FW_GetFacetGraphicDevice(ev, fFacet),
- aqTransform,
- aqClipShape);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewContext::~FW_CViewContext
- //----------------------------------------------------------------------------------------
-
- FW_CViewContext::~FW_CViewContext()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewContext::PrivAcquireTransform
- //----------------------------------------------------------------------------------------
-
- ODTransform* FW_CViewContext::PrivAcquireTransform(Environment* ev)
- {
- ODTransform* transform = FW_CopyAndRelease(ev, fView->AcquireViewContentToFrameTransform(ev));
-
- // compute transform to convert view to canvas coordinates
- FW_CAcquiredODTransform aqFrameTransform = fFacet->AcquireFrameTransform(ev, NULL);
- transform->PostCompose(ev, aqFrameTransform);
-
- return transform;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewContext::PrivAcquireClipShape
- //----------------------------------------------------------------------------------------
-
- ODShape* FW_CViewContext::PrivAcquireClipShape(Environment* ev)
- {
- ODShape* clipShape;
- if (fView->PrivIsTopPrintedView(ev))
- {
- // If I am the top printed view I need to use my extent not my visible bounds
- FW_CRect clipRect(FW_kZeroPoint, fView->GetExtent(ev));
- clipShape = ::FW_NewODShape(ev, clipRect);
- clipShape->SetGeometryMode(ev, kODLoseGeometry);
- }
- else
- {
- FW_CAcquiredODShape aqAggregateClipShape = fFacet->AcquireAggregateClipShape(ev, NULL);
-
- clipShape = ::FW_NewODShape(ev, fView->GetVisibleBounds(ev)); // visible bounds is in frame coordinates too
- clipShape->SetGeometryMode(ev, kODLoseGeometry);
-
- clipShape->Intersect(ev, aqAggregateClipShape);
-
- // convert it to view content coordinates
- fView->FrameToViewContent(ev, clipShape);
- }
-
- return clipShape;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CViewContext::Reset
- //----------------------------------------------------------------------------------------
-
- void FW_CViewContext::Reset()
- {
- FW_CAcquiredODTransform aqTransform = PrivAcquireTransform(fEnvironment);
- FW_CAcquiredODShape aqClipShape = PrivAcquireClipShape(fEnvironment);
-
- PrivReset(aqTransform, aqClipShape);
- }
-
-